﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Admin_Admin_CapNhatSanPhamDang2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int RowPerPage;
        int startIndex;
        int page;
        
        Button1.Attributes["OnClick"] = "return confirm('Bạn thật sự muốn xóa những sản phầm được chọn?');";
        Button2.Attributes["OnClick"] = "return confirm('Bạn thật sự muốn xóa những sản phầm được chọn?');";


        DataDSTableAdapters.SANPHAMTableAdapter spadapter = new DataDSTableAdapters.SANPHAMTableAdapter();
        if (Request["page"] != null)
            page = int.Parse(Request["page"]);
        else
            page = 0;
        RowPerPage = int.Parse(ConfigurationSettings.AppSettings["RowPerPage"]);
        startIndex = (page * RowPerPage);
        PageInterface1.currentPageName = GlobalFunctions.GetCurrentPageName();
        PageInterface1.currentPageNumber = page;
        PageInterface1.totalNumberOfPage = (int)spadapter.SANPHAM_TongSoDong() / RowPerPage;
        if ((int)spadapter.SANPHAM_TongSoDong() % RowPerPage != 0)
            PageInterface1.totalNumberOfPage++;

        if (Page.IsPostBack == false)
        {
            DataList_DSSP.DataSource = spadapter.SANPHAM_LayTatCa_Paged(startIndex, RowPerPage);
            DataList_DSSP.DataBind();
        }
            
        
       
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataDSTableAdapters.SANPHAMTableAdapter spadapter = new DataDSTableAdapters.SANPHAMTableAdapter();
        int? kq = 0;
        int count = 0;
        
        //Message box here
        for (int i = 0; i < DataList_DSSP.Items.Count; i++)
        {
            Label lb = (Label)DataList_DSSP.Items[i].FindControl("lbMaSP");
            CheckBox ck = (CheckBox)DataList_DSSP.Items[i].FindControl("ckSelect");
            if(ck.Checked == true)
            {
                //do delete seleted items
                string MaSP = lb.Text;
                spadapter.SANPHAM_XoaTheoMaSP(MaSP, ref kq);
                count++;
                if (kq != 0)
                    Response.Write("<script>alert('Lỗi xóa dữ liệu!')</script>");

            }
        }
        if (count == 0)
        {
            Response.Write("<script>alert('Không có dòng nào được chọn!')</script>");
            return;
        }
        Response.Write("<script>alert('Xóa thành công!'); window.location.href='/SMO/ChucNang/Admin/Admin_QuanLySanPham.aspx'</script>");
        //Response.Redirect("~/ChucNang/Admin/Admin_CapNhatSanPhamDang2.aspx");
            
    }

    protected void btnThemSP_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_ThemSanPham.aspx");
    }
}
